package com.campus.secondhand.entity;

import java.time.LocalDateTime;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import lombok.Data;

/**
 * 收藏实体类
 */
@Data
@Entity
@Table(name = "favorites", uniqueConstraints = {
        @UniqueConstraint(columnNames = { "user_id", "product_id", "purchase_request_id" })
})
public class Favorites {
    /**
     * 收藏ID，主键
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 用户ID，关联users表
     */
    @Column(name = "user_id", nullable = false)
    private Long userId;

    /**
     * 商品ID，关联products表，可以为null（当收藏求购信息时）
     */
    @Column(name = "product_id")
    private Long productId;

    /**
     * 求购信息ID，关联purchase_requests表，可以为null（当收藏商品时）
     */
    @Column(name = "purchase_request_id")
    private Long purchaseRequestId;

    /**
     * 收藏时间
     */
    @Column(name = "created_at", nullable = false, updatable = false)
    private LocalDateTime createdAt;
}